<template>
  <div style="margin: 20px">
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="ID" width="95">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column
        label="名字"
        width="100"
        prop="name"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        label="联系"
        width="150"
        prop="phone"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column label="内容" prop="content" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="updatetime" label="时间" width="200">
        <template slot-scope="{ row }">
          <span>{{ new Date(row.updatetime).toLocaleString() }}</span>
        </template>
      </el-table-column>

      <el-table-column
        class-name="status-col"
        label="操作"
        width="200"
        align="center"
      >
        <template slot-scope="{ row }">
          <ElButton @click="del(row._id)" type="danger" size="mini"
            >删除</ElButton
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="init"
    />
  </div>
</template>
<script>
import { addmessage, delmessage, getmessage } from "@/api/blog";
import Pagination from "@/components/Pagination";
export default {
  name: "ArticleMessage",
  data() {
    return {
      list: [],
      listLoading: false,
      total: 0,
      listQuery: {
        page: 1,
        limit: 10,
      },
    };
  },
  created() {
    this.init();
  },
  components: {
    Pagination,
  },
  methods: {
    init() {
      this.listLoading = true;
      getmessage(this.listQuery).then((res) => {
        console.log("评论列表=>>", res);
        this.list = res.data.flag;
        this.total = res.data.total;
        this.listLoading = false;
      });
    },
    del(_id) {
      delmessage({ _id }).then((res) => {
        console.log("删除评论=>>", res);
        res.flag ? this.init() : "";
        this.$message({ message: res.msg, type: "success" });
      });
    },
  },
};
</script>
<style lang='scss' scoped>
</style>